clear
clear matrix
clear mata
set matsize 4000
set maxvar 10000

*Note: first change working directory replication package folder

run "scripts/programs/program_data.do"
run "scripts/programs//program_regs.do"
run "scripts/programs/program_regtable.do"

/*********************************************************************************/
*Set program parameters
local radius = 20
local length = 1
/*********************************************************************************/

foreach angle in 7.5 30 60 {

	data anypop pop anyhu hu hudens lnpop popdens inc_pcincome inc_totinc inc_huxpcinc inc_pct_poverty ///
		count_res count_mobile count_sfr ///
		any_res val_res val_mobile val_sfr ///
		avgval_res avgval_mobile avgval_sfr ///
		race_pct_whitenh race_pct_amind ///
		race_pct_black race_pct_hisp tenure_pct_rent tri ///
		lnt lnint t1 t2 t3 t4 t5 t6 tmissing roadpcttot majorroad tritot habpolytot hablinetot wsimptot ///
		campground wilderness wind_diff ///
		using "data/`radius'-by-`length'km_`angle'deg/data_centroid.dta", ///
		maxlags(0) maxleads(0) burnt(centroid) tcuts(1,2,3,4,5,8)

	drop if fire_size < 1000

	/*************************	ANGLES TABLE  ******************************/

	/***Assessor's data***/

	gen x = (count_res != .)
	bysort firenum: egen assessor_data = sum(x)
	replace assessor_data = (assessor_data > 0)
	drop x

	replace race_pct_whitenh = 0 if count_res == 0
	replace inc_pct_poverty = 0 if count_res == 0
	replace inc_pcincome = 0 if count_res== 0
	replace tenure_pct_rent = 0 if count_res == 0

	local huvars anyhu hu inc_pcincome huxpcinc
	local indepvars habpolytot wsimptot campground wilderness tritot roadpcttot
	local firevars lnt tmissing lnint wind_diff majorroad
	local demvars `huvars' `indepvars'

	set matsize 4000
	local link cloglog
	local num = 10*`angle'
	regs y `demvars' `firevars' if complexfire != 1 & year > 2011, link(`link') cluster(firenum) save(ass`num') fe(firenum)

	/***Census data***/

	local huvars anyhu hu inc_pcincome huxpcinc
	local indepvars tritot roadpcttot habpolytot wsimptot campground wilderness
	local firevars lnt lnint majorroad tmissing wind_diff
	local demvars `huvars' `indepvars'

	set matsize 4000
	local link cloglog
	regs y `demvars' `firevars' if complexfire != 1, link(`link') cluster(firenum) save(census`num') fe(firenum)

}

local dir "Results\Angle_Table\"
capture mkdir `dir'

local assvars any_res count_res avgval_res val_res
local censusvars anyhu hu inc_pcincome huxpcinc

noi regtable ass75 ass300 ass600 census75 census300 census600 using "`dir'table_contents.tex" ///
 	, keep(`assvars' `censusvars' `indepvars' `firevars') stats(L) tex
